Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove log & data separation from base_local_service #4563

Merged
merged 5 commits into from
Jan 13, 2023

Conversation

mndeveci
Copy link
Contributor

@mndeveci mndeveci commented Jan 11, 2023

Which issue(s) does this change fix?

#4296
#3770

Why is this change necessary?

Before switching to use AWS Lambda RIE, sam local commands was trying to parse the output in STDOUT and were trying to distinguish the log messages vs the response of the lambda function.

With switching to AWS Lambda RIE, function response is now gathered through an API call and written to STDOUT here
and function logs are written to STDERR in this thread. With this change, only function response is written to STDOUT and only function logging is written to STDERR.

How does it address the issue?

By removing the special logic to parse STDOUT in order to distinguish the logs with actual function response.

What side effects does this change have?

N/A

Mandatory Checklist

PRs will only be reviewed after checklist is complete

  • Add input/output type hints to new functions/methods
  • Write design document if needed (Do I need to write a design document?)
  • Write/update unit tests
  • Write/update integration tests
  • Write/update functional tests if needed
  • make pr passes
  • make update-reproducible-reqs if dependencies were changed
  • Write documentation

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@mndeveci mndeveci marked this pull request as ready for review January 11, 2023 22:49
@mndeveci mndeveci requested a review from a team as a code owner January 11, 2023 22:49
@mndeveci mndeveci requested review from lucashuy and jfuss January 11, 2023 22:49
Copy link
Contributor

@jfuss jfuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall seems like a good change. Just a couple small comments I would like a response on before accepting.

@@ -81,7 +82,7 @@ def service_response(body, headers, status_code):

class LambdaOutputParser:
@staticmethod
def get_lambda_output(stdout_stream):
def get_lambda_output(stdout_stream: io.BytesIO) -> Tuple[str, bool]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if NamedTuple or a Dataclass would provide better readability and typing. I would not block on this but just stood out to me with the update.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do agree it would be better, but I didn't want to introduce more changes to this PR, I've only added some typing into the functions that is been changed.

lambda_response = stdout_data[last_line_position:].strip()

lambda_response = lambda_response.decode("utf-8")
lambda_response = stdout_stream.getvalue().decode("utf-8")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need the rstrip(b"\n") after the getvalue? We had it there before but not sure if it is strictly required anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've confirmed this by running local integration tests (some of them confirms the output of the command). So I believe we don't need that particular line

Copy link
Contributor

@hnnasit hnnasit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mndeveci mndeveci enabled auto-merge (squash) January 13, 2023 20:04
@mndeveci mndeveci merged commit f9a7674 into aws:develop Jan 13, 2023
@mndeveci mndeveci deleted the fix_local_logs_output_separation branch January 13, 2023 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants